window.onload=function(){
	var uid="hzzhimepanjin-15868403044";
	var pass="Hello1234";
	var sdk = new WSDK();
	/*
	 * 阿里百川登录
	 * */
    sdk.Base.login({
        uid:uid,
        appkey: 23667329,
        credential: pass,
        timeout: 4000,
        success: function(data){
           // {code: 1000, resultText: 'SUCCESS'}
           //console.log('login success', data);
		   getRecent();
        },
        error: function(error){
           // {code: 1002, resultText: 'TIMEOUT'}
           // console.log('login fail', error);
        }
    });
    /*
     * 获取最近的消息列表
     * */
    function getRecent(){
		sdk.Base.getRecentContact({
            count: 10,
            success: function(data){
            //  console.log('get recent contact success' ,data);
                var obj1=data.data.cnts;
                getUnreadMsgCount(obj1);
            },
            error: function(error){
                console.log('get recent contact success' ,error);
            }
        })
	}
    /*
	 * 获取未读消息
	 * */
    function getUnreadMsgCount(obj1){
    		sdk.Base.getUnreadMsgCount({
            count: 10,
            success: function(data){
            //   console.log('get unread msg count success' ,data);
                var obj2=data.data;
            //    console.log(obj2[0].msgCount);
                unRead(obj1,obj2);
            },
            error: function(error){
                console.log('get unread msg count fail' ,error);
            }
        });
    }
    
	/*
	 * 未读消息跟消息列表组合
	 * */
	function unRead(obj1,obj2){
		if(obj1.length>0){
			$(".nodata").hide();
		}else{
			$(".nodata").show();
		}
		
    		var a="";
		for(var i=0;i<obj1.length;i++){
			//console.log(obj1[i].uid);
			//console.log(obj1[i].nickname);
			a=obj1[i].nickname+","+a;
		}
		$.ajax({
			type : "POST",
			dataType : 'json',
			url : "/user/chatuserlistjson.htm",
			data : {
				"alibaichuanuids" : a,
			},
			success : function(data) {
				//console.log(data.length);
				ajaxReturn(obj1,obj2,data);
			}
		})
    }
	function ajaxReturn(obj1,obj2,obj3){
		for(var i=0;i<obj3.length;i++){
			var con=document.getElementById("con");
			var alink=document.createElement("a");
			alink.setAttribute("href", "/common/chat.html?mallName="+obj3[i].name+"&sellerAliId="+obj3[i].aliTongxueId);
			var div1=document.createElement("div");
			div1.className="listTab";
			var img1=document.createElement("img");
			//img1.src="http://tebieshuaiqidexiaogang.oschina.io/cszsimg/mallcomment/1488347137751IMG0712PNG";
			img1.src=obj3[i].imgBegin+"/"+obj3[i].portrait;
			var div2=document.createElement("div");
			div2.className="nickname";
			var text=document.createTextNode(obj3[i].name);
			div2.appendChild(text);
			div1.appendChild(img1);
			div1.appendChild(div2);
			
			for(var j=0;j<obj2.length;j++){
	    		if(obj1[i].uid==obj2[j].contact){
	    			console.log('wocao-------->'+obj2[j].contact);
	    			var div3=document.createElement("div");
	    			div3.className="unread";
	    			var msg=0;
	    			if(obj2[j].msgCount>=99){
	    				msg=99;
	    			}else{
	    				msg=obj2[j].msgCount;
	    			}
	    			var text2=document.createTextNode(msg);
	    			div3.append(text2);
	    			div1.appendChild(div3);
	    		}
	    	}	
			
			alink.appendChild(div1);
			con.appendChild(alink);
		}
	}
    
}